<template>
    <div class="login-contain">
        <div class="login-box">
            <div class="login-logo">
                <img src="../assets/logo.png" />
            </div>
            <el-form :model="loginForm" status-icon :rules="loginRules" ref="loginForm" class="loginForm">
                <el-form-item  prop="username">
                    <el-input type="text" v-model="loginForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item  prop="password">
                    <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item class="login_btn">
                    <el-button type="primary" @click="loginSubmit">提交</el-button>
                    <el-button @click="resetLoginForm">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return {
                loginForm:{
                    username:"",
                    password:""
                },
                loginRules: {
                    username: [
                        { required: true, message:"用户名不能为空" , trigger: 'blur' },
                        {min:3,max:12,message: "用户名长度应该为3-12位",trigger: 'blur'}
                    ],
                    password: [
                        { required: true, message:"输入密码不能为空" , trigger: 'blur' },
                        {min:6,max:12,message: "密码长度应该为5-12位",trigger: 'blur'}
                    ]
                },
            }
        },
        methods:{
            resetLoginForm(){
                this.$refs.loginForm.resetFields();
            },
            loginSubmit(){
                var that = this;
                this.$http.post("http://localhost:8081/login",this.loginForm).then(function (response) {
                    if(response.data.code==1){
                        that.$message.success("登录成功！");
                        that.$router.push("home")
                    }else{
                        that.$message.error("登陆失败");
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .login-contain{
        width: 100%;
        height: 100%;
        background-color: #2C5A69;
    }
    .login-box{
        width: 430px;
        height: 300px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        background-color: #ffffff;
        border-radius: 3px;
    }
    .login-logo{
        width: 130px;
        height: 130px;
        border-radius: 50%;
        border: 3px solid #ffffff;
        position: absolute;
        left: 50%;
        transform: translate(-50%,-50%);
        background-color: #ffffff;
        padding: 5px;
    }
    .login-logo img{
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #eeeeee;
    }
    .loginForm{
        width: 100%;
        position: absolute;
        bottom: 0px;
        padding: 0px 20px;
        box-sizing: border-box;

    }
    .login_btn{
        display: flex;
        justify-content: flex-end;
    }
</style>